<template>
  <div class="box-show">
    <div class="z gonggao">
      <el-page-header
        style="color: #999999"
        @back="$router.back(-1)"
        content="新增品牌"
      >
      </el-page-header>
      <div style="height: 20px"></div>
    </div>
    <div class="shuju">
      <el-row>
        <el-col :span="8">
          <el-form
            ref="form"
            :rules="rules"
            :model="form"
            label-width="80px"
            size="mini"
          >
            <el-form-item
              label="品牌名"
              prop="name"
              :rules="[{ required: true, message: '品牌名称不能为空' }]"
            >
              <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="英文名" prop="en_name">
              <el-input v-model="form.en_name"></el-input>
            </el-form-item>
            <el-form-item label="联系人" prop="phone">
              <el-input v-model="form.contacts_name"></el-input>
            </el-form-item>
            <el-form-item label="联系手机" prop="phone">
              <el-input v-model="form.phone"></el-input>
            </el-form-item>

            <el-form-item style="text-align: left">
              <el-button type="primary" @click="onSubmit('form')"
                >立即创建</el-button
              >
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { brand_save, brand_getInfoById } from "@/utils/do";
export default {
  name: "add",
  props: {},
  data() {
    return {
      form: {
        id: this.$route.params.id,
        name: "",
        en_name: "",
        contacts_name: "", // 分组的ID
        phone: "" // 仓库的唯一ID
      }
    };
  },
  components: {
    // 第三方组件实例化
  },
  computed: {},
  methods: {
    brand_getInfoById() {
      this.$store.commit("setIsLoading", true);
      let _this = this;
      brand_getInfoById(_this.form.id, res => {
        this.$store.commit("setIsLoading", false);
        console.log(res);
        if (res.code == 0) {
          _this.form = res.date;
        }
        _this.$message.error(res.msg);
      });
    },
    // 方法
    onSubmit(form) {
      this.$store.commit("setIsLoading", true);
      let _this = this;
      this.$refs[form].validate(valid => {
        if (valid) {
          console.log("提交参数", _this.form);
          brand_save(_this.form, res => {
            _this.$store.commit("setIsLoading", false);
            console.log(res);
            if (res.code != 0) {
              _this.$message.error(res.msg);
              return;
            }
            _this.$alert("修改品牌成功", "提醒", {
              confirmButtonText: "确定",
              callback: action => {
                console.log("点击了=", action);
                _this.$router.push("/Commodity/Brand/List");
              }
            });
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
  mounted() {
    this.brand_getInfoById();
  }
};
</script>

<style scoped>
@import "~@/assets/scss/index.css";
</style>
